<?php defined('IN_NWIDC') or exit('Access Invalid!');?>
<!-- <script src='/layer'></script> -->
<div class="page">
  <div class="fixed-bar">
    <div class="item-title">
      <h3>微信接口设置</h3>
      <ul class="tab-base">
        <li><a href="index.php?act=wechat" ><span>自定义菜单</span></a></li>
        <li><a href="javascript:;"  class='current'><span>回复设置</span></a></li>
        <li><a href="index.php?act=wechat&op=config" ><span>接口设置</span></a></li>
      </ul>
    </div>
  </div>
  <div class="fixed-empty"></div>

  <table class="table tb-type2" id="prompt">
    <tbody>
      <tr class="space odd">
        <th colspan="12"><div class="title">
            <h5><?php echo $lang['nc_prompts'];?></h5>
            <span class="arrow"></span></div></th>
      </tr>
      <tr>
        <td><ul>
          </ul></td>
      </tr>
    </tbody>
  </table>   
  <form method="post" id='form_list' action="index.php?act=wechat&op=reply">
    <div style="text-align:right;">
      <a class="btns" href="javascript:void(0);" id="new_item"><span>添加新回复</span></a>
    </div>
    <table class="table tb-type2">
      <thead>
        <tr class="thead">
          <th>关键字</th>
          <th>行为</th>
          <th>内容</th>
          <th>操作</th>
        </tr>

        <script type='tpl'>
          <tr class='first_menu'>
            <td>
              <div class='issub'></div>
              <input type="text" name='key_word[]'>
            </td>
            <td>
              <select name="type[]" id="">
                <option value="text">文字信息</option>
                <!-- <option value="news">图文信息</option> -->
              </select>
            </td>
            <td>
              <textarea name="reply[]" id="" cols="60" rows="5"></textarea>
            </td>
            <td>
              <a href="javascript::" class='del'>删除</a>
            </td>
          </tr>
        </script>
      </thead>

      <?php
        require_wechat();
        $wechat = new WeChat(-1);
        $answer_list = $wechat->get_answer_list();


 //        $ret = $wechat->set_menu_list(json_decode('{
 //     "button":[
 //     {  
 //          "type":"click",
 //          "name":"今日歌曲",
 //          "key":"V1001_TODAY_MUSIC"
 //      },
 //      {
 //           "name":"菜单",
 //           "sub_button":[
 //           {  
 //               "type":"view",
 //               "name":"搜索",
 //               "url":"http://www.soso.com/"
 //            },
 //            {
 //               "type":"view",
 //               "name":"视频",
 //               "url":"http://v.qq.com/"
 //            },
 //            {
 //               "type":"click",
 //               "name":"赞一下我们",
 //               "key":"V1001_GOOD"
 //            }]
 //       }]
 // }',true));

        // print_r($ret);

        
        // print_r($wechat->get_menu_list())
      ?>
      <script>
        var answer_list = <?php echo json_encode($answer_list); ?>;
        answer_list = eval(answer_list);

        // function make_item(data,is_submenu){
        //     var item = $(tpl);
        //     item.find('[name=name]').val(data.name);
        //     item.find('[name=url]').val(data.url);
        //     if(is_submenu){
        //         item.addClass('submenu').removeClass('first_menu');
        //     }
        //     box.append(item);
        // }
        $(function(){
          for(var i = 0; i < answer_list.length; i++){
            console.log(answer_list[i])
              var item = add_new_item();
              item.find('[name="key_word[]"]').val(answer_list[i].key_word);
              item.find('[name="reply[]"]').val(answer_list[i].reply);
          //     make_item(menu_list[i]);
              
          //     if(menu_list[i].sub_button){
          //         var buttons = menu_list[i].sub_button;
          //         for(var j in buttons){
          //             make_item(buttons[j],true);
          //         }
          //     }

          }
        })
      </script>
      <style>
        .submenu .issub{
            width: 25px;
            height: 15px;
            display: inline-block;
            *display: inline;
            margin-left: 10px;
            border-left: 1px solid #000;
            border-bottom: 1px solid #000;
        }

        .submenu .add_sub{
          display: none;
        }
      </style>
      <tbody class='tbody'>
        

      </tbody>

      <tfoot>
        <tr>
          <td  colspan='20'>
            <a href="javascript:;" id='save' class='btn'>保存设置</a>
          </td>
        </tr>
      </tfoot>

      <script>
        var layer = parent.layer;
        var tpl = $('[type=tpl]').html();
        <?php
          if(count($_POST)){
        ?>
        layer.msg('保存成功',{icon:1});
        <?php
          }
        ?>
        var box = $('.tbody');

        function add_new_item(){
          return $(tpl).appendTo($('.tbody'));
        }


        $('#new_item').click(function(){
            add_new_item();
        });

        $('.tbody').on('click','.del',function(){
            $(this).closest('tr').remove();
        });

        $('#save').click(function(){
          $('form').submit();
        });

      </script>

    </table>
  </form>
</div>




<script type="text/javascript" src="<?php echo RESOURCE_SITE_URL;?>/js/jquery-ui/jquery.ui.js"></script> 
<script type="text/javascript" src="<?php echo RESOURCE_SITE_URL;?>/js/jquery-ui/i18n/zh-CN.js" charset="utf-8"></script>
<link rel="stylesheet" type="text/css" href="<?php echo RESOURCE_SITE_URL;?>/js/jquery-ui/themes/ui-lightness/jquery.ui.css"  />
<script type="text/javascript">
$(function(){
    $('#time_from').datepicker({dateFormat: 'yy-mm-dd'});
    $('#time_to').datepicker({dateFormat: 'yy-mm-dd'});
    $('#ncexport').click(function(){
    	$('input[name="op"]').val('export_step1');
    	$('#formSearch').submit();
    });
    $('#ncsubmit').click(function(){
    	$('input[name="op"]').val('list');
    	$('#formSearch').submit();
    });
    $('#ncdelete').click(function(){
        $('#delago').val($('#delago1').val());
    	$('input[name="op"]').val('list_del');$('#formSearch').submit();
    });
});
</script>
